package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 大攻略下的分类
 */
@Getter
@Setter
@JsonIgnoreProperties("handler")//mvc将此对象转换成json时，忽略handle这条属性
public class StrategyCatalog extends BaseDomain {

    public static final boolean STATE_NORMAL = true;
    public static final boolean STATE_DISABLE = false;

    private String name;//分类名

    private Strategy strategy;//所属的大攻略

    private Integer sequence;//序号

    private List<StrategyDetail> details=new ArrayList<>();

    private Boolean state = true;//状态

    public String getStateName() {
        if (state != null) {
            if (state == STATE_NORMAL) {
                return "启用";
            }
            return "禁用";
        }
        return "";
    }

    public String getJsonString() {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("name", name);
        if (strategy != null) {
            map.put("strategyId", strategy.id);
        }
        map.put("sequence", sequence);
        map.put("state", state);
        return JSONUtil.toJSONString(map);
    }
}